<template>
  <div class="dashboard-container">
    <div class="app-container">
      <page-tools :show-before="true">
        <template slot="before">
          <span>当前审批中 本月审批通过 本月审批驳回</span>
        </template>

        <template slot="after">
          <el-button size="small" type="primary" @click="$router.push({path:'/approvals/securitySetting'})">流程设置</el-button>
        </template>
      </page-tools>

      <!-- 放置表格和分页 -->
      <el-card>
        <el-table
          ref="approvalTable"
          :data="approvalList"
          style="width: 100%"
          :default-sort="{prop: 'date', order: 'descending'}"
        >
          <el-table-column type="selection" width="50px" />
          <el-table-column type="index" label="序号" width="80px" />
          <el-table-column label="审批类型" width="150px" prop="processName" sortable />
          <el-table-column label="申请人" width="150px" prop="username" sortable />
          <el-table-column label="当前审批人" width="280px" prop="procCurrNodeUserName" sortable />
          <el-table-column label="审批发起时间" sortable>
            <template slot-scope="scope">
              <span>{{ scope.row.procApplyTime | formatDate }}</span>
            </template>
          </el-table-column>
          <el-table-column label="审批状态" sortable>
            <template slot-scope="scope">
              <span v-if="scope.row.processState === '1'" class="rovalsState">
                <em class="stay" />
                审批中
              </span>
              <span v-if="scope.row.processState === '2'" class="rovalsState">
                <em class="pass" />
                审批通过
              </span>
              <span v-if="scope.row.processState === '3'" class="rovalsState">
                <em class="nopass" />
                审批不通过
              </span>
              <span v-if="scope.row.processState === '4'" class="rovalsState">
                <em class="remove" />
                撤销
              </span>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="{row}">
              <el-button type="text" @click="detail(row)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="pagination">
          <el-pagination
            background
            :total="pagination.total"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="10"
            layout="sizes,prev,pager,next,jumper"
            @current-change="currenChange"
            @size-change="sizeChange"
          />
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getApprovalList } from '@/api/approvals'
export default {
  data() {
    return {
      approvalList: [],
      userId: this.$store.state.user.userInfo.userId,
      pagination: {
        page: 1, // 页面
        pageSize: 10, // 每页条数
        total: 1 // 总条数
      }
      // newPage:''
    }
  },
  mounted() {
    this.getApprovalList()
  },
  methods: {
    // 查询审批的详情数据
    async getApprovalList() {
      const res = await getApprovalList(this.pagination)
      console.log(res)
      this.pagination.total = res.total
      console.log(this.pagination.total)
      this.approvalList = res.rows
    },
    // 点击查看详细数据
    detail(obj) {
      console.log(obj)
      const name = obj.processName
      console.log(name)
      if (name === '请假') {
        this.$router.push({ path: '/approvals/leaveApproval/' + obj.processId })
      } else if (name === '离职') {
        this.$router.push({ path: '/approvals/quitApproval/' + obj.processId })
      } else {
        this.$router.push({ path: '/approvals/overtimeApproval/' + obj.processId })
      }
    },
    currenChange(currentpage) {
      this.pagination.page = currentpage
      this.getApprovalList()
    },
    sizeChange(currentPages) {
      console.log(currentPages)
      this.pagination.pageSize = currentPages
      this.getApprovalList()
    }
  }
}
</script>

<style lang="scss" scoped>
.pagination {
  display: flex;
  justify-content: flex-end;
}
.rovalsState {
  display: flex;
  align-items: center;
  .stay,
  .pass,
  .nopass,
  .remove {
    display: block;
    width: 5px;
    height:5px;
    border-radius: 50%;
    background-color: #3e90ec;
    margin-right: 5px;
  }
  .pass {
    background-color: #41a94f;
  }
  .nopass {
    background-color: #e1362f;
  }
  .remove {
    background-color: #bfbfbf;
  }
}

</style>
